﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace anks.Lib.Config
{
    public class ConfigNode
    {
        public string nodeValue { get; set; }
        public bool asBool {
            get
            {
                return Convert.ToBoolean(nodeValue);
            }
            set
            {
                nodeValue = Convert.ToString(value);
            }
        }
        public int asInt {
            get
            {
                return Convert.ToInt32(nodeValue);
            }
            set
            {
                nodeValue = Convert.ToString(value);
            }
        }
        public string asString {
            get
            {
                return Convert.ToString(nodeValue);
            }
            set
            {
                nodeValue = Convert.ToString(value);
            }
        }

    }

    public class ConfigGroup : Dictionary<string, ConfigNode>
    {
        public ConfigNode AddNode(string name)
        {
            ConfigNode node = new ConfigNode();
            Add(name, node);
            return node;
        }

        public ConfigNode AddNode(string name, string value)
        {
            ConfigNode node = AddNode(name);
            node.asString = value;
            return node;
        }

        public ConfigNode AddNode(string name, bool value)
        {
            ConfigNode node = AddNode(name);
            node.asBool = value;
            return node;
        }

        public ConfigNode AddNode(string name, int value)
        {
            ConfigNode node = AddNode(name);
            node.asInt = value;
            return node;
        }
    }

    public class Config : Dictionary<string, ConfigGroup>
    {
        public ConfigGroup AddGroup(string name)
        {
            ConfigGroup group = new ConfigGroup();
            Add(name, group);
            return group;
        }
    }
}
